package com.app.mycomposedemo.ui.components


import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Divider
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.app.mycomposedemo.data.ArticleData
import com.app.mycomposedemo.ui.theme.Gray2233
import com.app.mycomposedemo.ui.theme.Gray33
import com.app.mycomposedemo.ui.theme.Gray99

/**
 * 文章标题布局
 */
@Composable
fun ArticleColumnItem(article: ArticleData) {

    Column(modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)) {
        Text(
            text = article.title,
            color = Gray33,
            fontSize = 16.sp,
            maxLines = 2,
            overflow = TextOverflow.Ellipsis
        )

        Row(
            modifier = Modifier.padding(top = 4.dp),
            verticalAlignment = Alignment.CenterVertically,
            horizontalArrangement = Arrangement.End
        ) {
            Text(
                modifier = Modifier.weight(1f),
                text = article.source,
                color = Gray99,
                fontSize = 12.sp,
                maxLines = 1,
                overflow = TextOverflow.Ellipsis
            )
            Text(
                modifier = Modifier.padding(start = 8.dp),
                text = article.date,
                color = Gray99,
                fontSize = 12.sp,
                maxLines = 1
            )
        }
        Divider(modifier = Modifier.padding(top =16.dp), color = Gray2233)
    }
}

@Preview(showSystemUi = true)
@Composable
fun ArticleColumnItemPreview() {
    ArticleColumnItem(
        ArticleData(
            title = "人社部向疫情防控期参与复工复产的劳动者表人社部向疫情防控期参与复工复产的劳动者表",
            source = "“学习强国”学习平台",
            date = "2020-02-10"
        )
    )
}

